/**
 * 大厅俱乐部组件
 */
var ClubUnit = Unit.extend({
    //按钮列表: 0：click；2：name；3：spine名字及动画名字['fire','fly', true, x, y]；

    _ccsFileName: res.ClubUnit_json,
    _btnsList: [
        ['_clickClub', 'btn_club'],
        ['_clickCreateRoom', 'btn_createroom'],
        ['_clickMatchRoom', 'btn_match'],
        ['_clickJoinRoom', 'btn_joinroom']
    ],
    initUnit: function () {
        this._initParams();
    },
    /**
     * 初始化根据参数信息
     * @protected
     */
    _initParams: function () {
        if(hall.res.sp_jiemian_json){
            var sp_jiemian = playSpine(hall.res.sp_jiemian_json, 'animation', true);
            sp_jiemian.setPosition(cc.p(24,60));
            sp_jiemian.setScale(0.9);
            this._nodeList['btn_club'].addChild(sp_jiemian);
        }

        if(hall.res.sp_kailemajiang_tx_json){
            var sp_julebu = playSpine(hall.res.sp_kailemajiang_tx_json, 'qinyouquan', true);
            sp_julebu.setPosition(cc.p(this._nodeList['btn_club'].getContentSize().width/2,
                55));
            this._nodeList['btn_club'].addChild(sp_julebu);

            var sp_match = playSpine(hall.res.sp_kailemajiang_tx_json, 'jinbichang', true);
            sp_match.setPosition(cc.p(this._nodeList['btn_createroom'].getContentSize().width/2,
                this._nodeList['btn_createroom'].getContentSize().height/2));
            this._nodeList['btn_createroom'].addChild(sp_match);


            var sp_join = playSpine(hall.res.sp_kailemajiang_tx_json, 'jiarufangjian', true);
            sp_join.setPosition(cc.p(this._nodeList['btn_joinroom'].getContentSize().width/2,
                this._nodeList['btn_joinroom'].getContentSize().height/2));
            this._nodeList['btn_joinroom'].addChild(sp_join);
        }

        if(hall.res.lizi_anniu && cc.sys.isNative){
            var lizi = cc.ParticleSystem.create(hall.res.lizi_anniu);
            lizi.setPosition(cc.p(this._nodeList['btn_club'].getContentSize().width/2,
                this._nodeList['btn_club'].getContentSize().height/2));
            this._nodeList['btn_club'].addChild(lizi);

            var lizi2 = cc.ParticleSystem.create(hall.res.lizi_anniu);
            lizi2.setPosition(cc.p(this._nodeList['btn_match'].getContentSize().width/2,
                this._nodeList['btn_match'].getContentSize().height/2));
            this._nodeList['btn_match'].addChild(lizi2);
        }
    },
    _initClickListeners: function () {
        this._super();
        this._clickListeners = {};
        for (var i = 0; i < this._btnsList.length; i++) {
            var _name = this._btnsList[i][1];
            var btn = this._nodeList[_name];
            if (btn) {
                btn.setTag(i);
                this._clickListeners[_name] = '_clickButton';
            }
        }
    },
    /**
     * 点击按钮时
     * @param btn:点击的按钮
     * @private
     */
    _clickButton: function (btn) {
        var tag = btn.getTag();

        var param = this._btnsList[tag];
        if (!param) return;
        //点击
        var _click = param[0];
        if (_click && _click.length > 0) {
            window.eventManager.dispatchEvent(EventKey.HallBoardBtnEvent, _click);
        }
    },
});